package com.aichat.ai_chatbackend.satoken;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;

import com.aichat.ai_chatbackend.constant.UserConstant;
import com.aichat.ai_chatbackend.model.entity.User;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static com.aichat.ai_chatbackend.constant.UserConstant.USER_LOGIN_STATE;


@Component
@Slf4j
public class StpInterfaceImpl implements StpInterface {

    /**
     * 返回一个账号所拥有的权限码集合
     * @param o
     * @param s
     * @return
     */
    @Override
    public List<String> getPermissionList(Object o, String s) {
        return new ArrayList<>();
    }




    /**
     * 返回一个账号所拥有的角色标识集合
     * @param loginId
     * @param loginType
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        User user = (User) StpUtil.getSessionByLoginId(loginId).get(USER_LOGIN_STATE);
        if (user == null || user.getRole() == null) {
            return new ArrayList<>();
        }
        return Collections.singletonList(user.getRole().toString());
    }
}
